package com.tianshuo.construct.main;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;

import java.io.IOException;
import java.util.Set;

/**
 * @ClassName : MetaDataApplicationContext
 * @Description : metadata数据测试，ClassMetaData，AnnotationMetaData,MetaDataReader
 * @Author : tianshuo
 * @Date: 2021-09-12 18:03
 */
public class MetaDataApplicationContext {


    public static void main(String[] args) throws IOException {


        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        SimpleMetadataReaderFactory simpleMetadataReaderFactory = new SimpleMetadataReaderFactory();
        MetadataReader metadataReader = simpleMetadataReaderFactory.getMetadataReader("com.tianshuo.condition.config.ConditionalConfig");

        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
        annotationMetadata.getAnnotationTypes().forEach(System.out::println);

        // 获取带有@Bean注解的方法名称
        Set<MethodMetadata> bean = annotationMetadata.getAnnotatedMethods("org.springframework.context.annotation.Bean");
        bean.forEach(methodMetadata -> System.out.println("a : "+methodMetadata.getMethodName()));

        ClassMetadata classMetadata  = metadataReader.getClassMetadata();
        System.out.println(classMetadata.getClassName());

    }
}

